package com.offcn.entity;

public class Page {
    private int curPage;//当前页
    private int pageSize;//页容量
    private int nextPage;//下一页
    private int prevPage;//上一页
    private int rows;//总记录数
    private int endPage;//总页数
    private int startIndex;//每一页的起始行下标
    //总体初始化
    public Page(int rows,String curPage) {
        this.rows = rows;
        this.pageSize=5;
        initCurPage(curPage);
        initPrevPage();
        initEndPage();
        initNextPage();
        initStartIndex();

    }
    //属性初始化
    //初始化当前页
    public void initCurPage(String curPage){
        //当页面不传当前页，或当前页为空字符串默认首页
        if(curPage==null||"".equals(curPage)){
            this.curPage = 1;
        }else {
            this.curPage=Integer.valueOf(curPage);
        }
    }
    //初始化上一页
    public void initPrevPage(){
        if(curPage>1){
            prevPage=curPage-1;
        }else {
            prevPage=1;
        }
    }
    //初始化下一页
    public void initNextPage(){
        if(curPage<endPage){
            nextPage=curPage+1;
        }else {
            nextPage=endPage;
        }
    }
    //初始化总页数
    public void initEndPage(){
        if(rows%pageSize==0){
            endPage=rows/pageSize;
        }else {
            endPage=rows/pageSize+1;
        }
    }
    //初始化起始行
    public void initStartIndex(){
        startIndex=(curPage-1)*pageSize;
    }

    public int getCurPage() {
        return curPage;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }
}
